package com.jhrc.portal.ws.heartbeat.impl;

import com.jhrc.portal.ws.heartbeat.HeartBeat;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * 【chenhsong的ping包】
 *
 * @Author: luanxd
 * @Date: 2020-05-19 10:13
 */
public class ChenhsongHeartBeatImpl implements HeartBeat {
    int seq=0;

    /**
     * 【心跳发送】
     * @param ctx
     */
    @Override
    public void ping(ChannelHandlerContext ctx) {
        Channel channel = ctx.channel();
        if (channel != null){
            if (channel.isActive()){
                String hStr = "{ $type: \"Alive\", sequence:" + (seq++) + ", priority: -10 }";
                TextWebSocketFrame textWebSocketFrame = new TextWebSocketFrame(hStr);
                channel.writeAndFlush(textWebSocketFrame);
            }
        }
    }
}
